package com.fitz.core.filter;

import com.fitz.core.context.FilterConstants;
import com.fitz.core.context.RequestContext;
import com.fitz.core.util.OkHttpUtil;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;

//@Component
public class SimpleRouteFilter extends AbstractFilter{

    @Override
    public String routeType() {
        return FilterConstants.ROUTE_TYPE;
    }

    @Override
    public int order() {
        return 1000;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext rtx = RequestContext.getCurrentContext();
        HttpServletRequest request = rtx.getRequest();
        //临时
        rtx.setUrl("http://127.0.0.1:8081/forward/test");
        String url = rtx.getUrl();
        HashMap<String, String> params = buildRequestQueryParams(request);
        try {
            return OkHttpUtil.getInstance().get(url,params);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
